package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.OrderList;

public class OrderListParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {
		OrderList orderList = new OrderList();

		ListModelParser.parseListModel(orderList, jsonObject);
		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray array = data.optJSONArray("items");
		orderList.items = new ArrayList<OrderList.Order>();
		for (int i = 0; array != null && i < array.length(); i++) {
			JSONObject object = array.optJSONObject(i);
			if (object != null) {
				OrderList.Order order = new OrderList.Order();
				order.datetime = object.optString("datetime", "");
				order.name = object.optString("name", "");
				order.orderid = object.optString("orderid", "");
				order.persons = object.optString("persons", "");
				order.phone = object.optString("phone", "");
				order.reversetime = object.optString("reversetime", "");
				order.type = object.optString("type", "");
				orderList.items.add(order);
			}
		}

		return orderList;

	}
}
